﻿using StoryTeller.Infrastructure.DataAccess.Parser;
using StoryTeller.Infrastructure.DataAccess.DAL.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StoryTeller.Infrastructure.DataAccess.DAL
{
    public class ContributionRatingDAL : BaseDAL, IContributionRatingDAL
    {
        public void Insert(Domain.ContributionRating entidade)
        {
            Entities.ContributionRating.Add(entidade.ParseDomainToEntity());

            Save();
        }

        public void Delete(int userId, int contributionId)
        {
            EContributionRating cat = Entities.ContributionRating.First(c => c.IdContribution == contributionId && c.IdUser == userId);

            if (cat != null)
            {
                Entities.ContributionRating.Remove(cat);

                Save();
            }
        }

        public ICollection<Domain.ContributionRating> Select(int contributionId)
        {
            ICollection<EContributionRating> coll = Entities.ContributionRating.Where(s => s.IdContribution == contributionId).ToList();

            return coll.Select(c => c.ParseEntityToDomain()).ToList();
        }
    }
}
